package com.hyw.trace.configuration.sample.meta.mq;

import java.util.Objects;

import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import com.hyw.trace.configuration.meta.TraceEvent;
import com.hyw.trace.configuration.sample.meta.IMQOutcome;

/**
 * 这是一个基于MQ投递的默认实现方式, 会对传输的对象 , 以JSON的方式进行转换输出
 * 
 * @author hongyu
 */
public class MQOutcome implements IMQOutcome {

  private MessageChannel channel;

  public MQOutcome(MessageChannel channel) {
    Objects.requireNonNull(channel);
    this.channel = channel;
  }

  @Override
  public void storage(TraceEvent data) {
    channel.send(MessageBuilder.withPayload(data).build());
  }
}
